package com.atguigu.spring;

import com.atguigu.spring.bean.Cat;
import com.atguigu.spring.bean.Person;
import com.atguigu.spring.config.MyConfig;
import org.springframework.context.ApplicationContext;
import org.springframework.context.annotation.AnnotationConfigApplicationContext;

public class AnnotationMainTest {
	public static void main(String[] args) {
		ApplicationContext applicationContext
				= new AnnotationConfigApplicationContext(MyConfig.class);
		Person bean = applicationContext.getBean(Person.class);
		System.out.println(bean);
		for (String beanDefinitionName : applicationContext.getBeanDefinitionNames()) {
			System.out.println(beanDefinitionName);
		}
		System.out.println("-----------------");
		Cat bean1 = applicationContext.getBean(Cat.class);
		Cat bean2 = applicationContext.getBean(Cat.class);
		System.out.println(bean1 == bean2);
		System.out.println("-----------------");
		Person bean3 = applicationContext.getBean(Person.class);
		Person bean4 = applicationContext.getBean(Person.class);
		//person 是单实例的 所以person里边引用的cat也是一样的 prototype是不会生效的
		//@Lookup 放在get方法上赋值的时候 可以使prototype生效
		System.out.println(bean3.getCat() == bean4.getCat());

	}
}
